package cn.hbads.version.domain.version.model;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * <b> 数据版本/数据日历版本类型 </b>
 *
 * @author : yvvb
 * @date : 2025/5/5
 */
public enum VersionType {
    NO_CHANGE(0, "无变化"),
    CREATE(1, "新增"),
    MODIFY(2, "修改"),
    DELETE(3, "删除"),
    ;

    public static final Map<VersionType, Set<VersionType>> RATIONAL_TRANSFER_RULES = new HashMap<>();

    static {
        RATIONAL_TRANSFER_RULES.put(NO_CHANGE, Set.of(MODIFY, DELETE));
        RATIONAL_TRANSFER_RULES.put(CREATE, Set.of(DELETE));
        RATIONAL_TRANSFER_RULES.put(MODIFY, Set.of(MODIFY, DELETE));
        RATIONAL_TRANSFER_RULES.put(DELETE, Set.of(DELETE));
    }

    private final int code;
    private final String name;

    VersionType(int code, String name) {
        this.code = code;
        this.name = name;
    }

    public static boolean checkTransferValid(VersionType from, VersionType to) {
        final var allowTransitionSet = RATIONAL_TRANSFER_RULES.get(from);
        return allowTransitionSet.contains(to);
    }
}
